package com.codedancer.campus.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.codedancer.campus.common.core.BaseMapper;
import com.codedancer.campus.enums.DynamicStatus;
import com.codedancer.campus.po.Dynamic;
import com.codedancer.campus.qo.dynamic.DynamicSearchQo;
import java.util.List;
import org.apache.ibatis.annotations.Param;

public interface DynamicMapper extends BaseMapper<Dynamic> {

    /**
     * 分页查询动态(管理端)
     *
     * @param dynamicPage
     * @param dynamicSearchQo
     * @return
     */
    IPage<Dynamic> page2Manager(Page<Dynamic> dynamicPage,
        @Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);

    /**
     * 查询需要导出的动态
     *
     * @param dynamicSearchQo
     * @return
     */
    List<Dynamic> listExportData(@Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);

    /**
     * 分页查询动态(客户端)
     *
     * @param dynamicPage
     * @param dynamicSearchQo
     * @return
     */
    IPage<Dynamic> page2Client(Page<Dynamic> dynamicPage,
        @Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);

    /**
     * 动态详情
     * @param uuid
     * @return
     */
    Dynamic detail(String uuid);

    /**
     * 查询用户发布的动态
     *
     * @param dynamicPage
     * @param dynamicSearchQo
     * @return
     */
    IPage<Dynamic> page2User(Page<Dynamic> dynamicPage,
        @Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);

    /**
     * 分页查询某个圈子下的动态
     *
     * @param dynamicPage
     * @param dynamicSearchQo
     * @return
     */
    IPage<Dynamic> pageByCircleUuid(Page<Dynamic> dynamicPage,
        @Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);

    /**
     * 根据圈子查询动态数量
     *
     * @param uuid
     * @return
     */
    default int countByCircleUuid(String uuid) {
        LambdaQueryWrapper<Dynamic> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Dynamic::getCircleUuid, uuid);
        lambdaQueryWrapper.eq(Dynamic::getStatus, DynamicStatus.PASSED);
        return selectCount(lambdaQueryWrapper);
    }

    /**
     * 分页查询某个圈子下的动态(管理端)
     *
     * @param dynamicPage
     * @param dynamicSearchQo
     * @return
     */
    IPage<Dynamic> pageByCircleUuid2Manager(Page<Dynamic> dynamicPage,
        @Param("dynamicSearchQo") DynamicSearchQo dynamicSearchQo);
}
